﻿<Window x:Class="OpenRiaServices.VisualStudio.DomainServices.Tools.BusinessLogicClassDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:tools="clr-namespace:OpenRiaServices.VisualStudio.DomainServices.Tools"
    Height="582" MinHeight="582" MinWidth="450" WindowStyle="ToolWindow" SizeToContent="Width"
    Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
    Title="{x:Static tools:Resources.BusinessLogicClass_Dialog_Title}"
    FocusManager.FocusedElement="{Binding ElementName=DomainServiceClassNameTextBox}" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignWidth="450">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="Help" Executed="CommandBinding_Executed" />
    </Window.CommandBindings>
    <Grid Margin="5">

        <Grid.Resources>
            
            <Style x:Key="ListViewItemStyle" TargetType="{x:Type ListViewItem}">
                <Setter Property="Margin" Value="0,1,0,0"/>
                <Setter Property="Height" Value="21"/>
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="VerticalContentAlignment" Value="Stretch" />
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition MinHeight="250" Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0">
            <TextBlock Name="DomainServiceClassNameLabel" Margin="5" HorizontalAlignment="Left" 
                       TextWrapping="Wrap" Text="{x:Static tools:Resources.BusinessLogicClass_DomainServiceClassName_Text}"/>
            
            <TextBox Name="DomainServiceClassNameTextBox" Margin="5" BorderThickness="1" BorderBrush="Black" MaxLines="1" 
                     IsReadOnly="True" TextWrapping="Wrap" Text="{Binding Path=ClassName}"
                     AutomationProperties.Name="{x:Static tools:Resources.BusinessLogicClass_DomainServiceClassName_Text}"/>
            
            <CheckBox Name="EnableClientAccessCheckbox" Margin="7,5,5,5"  HorizontalAlignment="Left" 
                      IsChecked="{Binding Path=CurrentContextViewModel.IsClientAccessEnabled, Mode=TwoWay}"
                      ToolTip="{x:Static tools:Resources.BusinessLogicClass_EnableClientAccess_Tooltip}" >
                <TextBlock TextWrapping="Wrap" Text="{x:Static tools:Resources.BusinessLogicClass_EnableClientAccess_Text}" />
            </CheckBox>

            <CheckBox Name="EnableODataEndpointCheckbox" Margin="7,2,5,5" HorizontalAlignment="Left" 
                      IsChecked="{Binding Path=CurrentContextViewModel.IsODataEndpointEnabled, Mode=TwoWay}" 
                      ToolTip="{x:Static tools:Resources.BusinessLogicClass_EnableODataEndpoint_Tooltip}" >
                <TextBlock TextWrapping="Wrap" Text="{x:Static tools:Resources.BusinessLogicClass_EnableODataEndpoint_Text}" />
            </CheckBox>
        </StackPanel>

        <StackPanel Grid.Row="1">
            <TextBlock Margin="5" HorizontalAlignment="Left" Name="AvailableContextLabel" 
                       TextWrapping="Wrap" Text="{x:Static tools:Resources.BusinessLogicClass_AvailableContexts_Text}" />
            <ComboBox Margin="5" Name="ContextComboBox" ItemsSource="{Binding Path=ContextViewModels, Mode=OneWay}" DisplayMemberPath="Name" SelectionChanged="ContextComboBox_SelectionChanged"
                      AutomationProperties.Name="{x:Static tools:Resources.BusinessLogicClass_AvailableContexts_Text}"/>
            <TextBlock Margin="5" TextWrapping="Wrap" Text="If no entities are shown you may need to build the project first or install an additional NuGet package such as OpenRiaServices.EntityFramework." />
        </StackPanel>

        <ListView Grid.Row="2" Margin="5" Name="EntityListView" ItemsSource="{Binding Path=CurrentContextViewModel.Entities}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemContainerStyle="{StaticResource ListViewItemStyle}"
                  AutomationProperties.Name="{x:Static tools:Resources.BusinessLogicClass_ListView_Entity_Header}">
            <ListView.Resources>
                <DataTemplate x:Key="EntityTemplate">
                    <StackPanel Orientation="Horizontal">
                        <CheckBox Name="IncludeEntityCheckbox" IsChecked="{Binding Path=IsIncluded, Mode=TwoWay}" IsEnabled="{Binding Path=CanBeIncluded}" Click="CheckBox_Clicked" AutomationProperties.Name="{Binding Path=Name}"/>
                        <TextBlock Margin="3,0,0,0" Text="{Binding Path=Name, Mode=OneWay}" />
                    </StackPanel>
                </DataTemplate>
                <DataTemplate x:Key="EditableTemplate">
                    <CheckBox Name="EnableEditingCheckbox" HorizontalAlignment="Center" IsChecked="{Binding Path=IsEditable, Mode=TwoWay}" IsEnabled="{Binding Path=CanBeEdited}" Click="CheckBox_Clicked" AutomationProperties.Name="{Binding Path=Name, StringFormat={x:Static tools:Resources.BusinessLogicClass_ListView_EnableEditing_Automation}}"/>
                </DataTemplate>
            </ListView.Resources>
            <ListView.View>
                <GridView AllowsColumnReorder="False">
                    <!-- Column [0] is "Entities" and Column[1] is "Enable Editing" -->
                    <GridViewColumn Width="Auto" CellTemplate="{StaticResource EntityTemplate}" Header="{x:Static tools:Resources.BusinessLogicClass_ListView_Entity_Header}"/>
                    <GridViewColumn Width="Auto" CellTemplate="{StaticResource EditableTemplate}" Header="{x:Static tools:Resources.BusinessLogicClass_ListView_EnableEditing_Header}"/>
                </GridView>
            </ListView.View>
        </ListView>

        <CheckBox Grid.Row="3" Margin="5" Name="GenerateMetadataCheckbox" IsChecked="{Binding Path=IsMetadataClassGenerationRequested}" 
                  IsEnabled="{Binding Path=IsMetadataClassGenerationAllowed}" IsEnabledChanged="CheckBox_ClassMetadata_EnabledChanged" >
            <TextBlock TextWrapping="Wrap" Text="{x:Static tools:Resources.BusinessLogicClass_Metadata_Text}" />
        </CheckBox>

        <StackPanel Grid.Row="4" Margin="5" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Name="OKButton" Margin="0,0,5,0" IsDefault="true" Click="OKButton_Click" MinWidth="75" Content="{x:Static tools:Resources.BusinessLogicClass_OK_Button_Text}" />
            <Button Name="CancelButton" IsCancel="true" Click="CancelButton_Click" MinWidth="75" Content="{x:Static tools:Resources.BusinessLogicClass_Cancel_Button_Text}" />
        </StackPanel>
    </Grid>
</Window>
